﻿using System;
using System.Text;
using System.Web.UI;
using EmptyWallGallery.Core;

namespace EmptyWallGallery.FrontEnd
{
    public partial class Default : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            BindData();

            Page.Title = Configs.WebTitle;
            Page.MetaDescription = Configs.WebDescription;
        }

        public void BindData()
        {
            var item = Core.BLL.Articles.Instance.GetTopArticle(1, Configs.SiteId, 2);
            if (item.Count == 0) return;

            //get content article from xml
            var objArticle = Core.BLL.Articles.Instance.ReadXmlbyId(
                Convert.ToString(item[0].ArticlesId),
                Convert.ToString(Convert.ToDateTime(item[0].CreatedDate).Day),
                Convert.ToString(Convert.ToDateTime(item[0].CreatedDate).Month),
                Convert.ToString(Convert.ToDateTime(item[0].CreatedDate).Year));

            if (objArticle == null) return;

            title.InnerHtml = objArticle.Title;
            body.InnerHtml = Server.HtmlDecode(objArticle.Body);
            //PostInfo.InnerHtml = "Đăng vào: " +
            //                         Convert.ToDateTime(objArticle.ReleaseDate).AddHours(Configs.TimeLine).ToString(
            //                             "dd-MM-yyyy HH:mm tt");

            //Update View
            Core.BLL.Articles.Instance.UpdateViewCount(objArticle.ArticlesId);
        }
    }
}